#!/usr/bin/env python
#coding=utf-8
import os
import codecs
import locale
import types
import wx
#def GetCurrDir(): return os.path.dirname("cndevOE.exe")



try:
    defaultencoding = locale.getdefaultlocale()[1]
except:
    defaultencoding = None

if not defaultencoding:
    defaultencoding = 'utf-8'
try:
    codecs.lookup(defaultencoding)
except:
    defaultencoding = 'utf-8'

try:
    defaultfilesystemencoding = sys.getfilesystemencoding()
except:
    defaultfilesystemencoding = None

if not defaultfilesystemencoding:
    defaultfilesystemencoding = 'ascii'
try:
    codecs.lookup(defaultfilesystemencoding)
except:
    defaultfilesystemencoding = 'ascii'




def GetCurrDir(): 
    path = os.path.dirname(__file__)
    if os.path.isfile(path):
        path = os.path.dirname(os.path.abspath(path))
    #print decode_string(path)
    return unicode(path,'gb2312')
    #unicode_path(path)
    #return os.path.dirname("cndevOE.exe")
def GetTransforSymbol():
    return {"&lt;":"<","&gt;":">","&quot;":'"',"&#40;":"(","&#41;":")","&#32;":" ","&#64;":"@","&amp;":"&"}

def unicode_path(path, encoding=defaultfilesystemencoding):
    """convert path to unicode
    """
    return decode_string(path)

def encode_path(path, encoding=defaultfilesystemencoding):
    return encode_string(path, encoding)


def decode_string(string, encoding=None):
    """convert string to unicode

    If the second parameter encoding is omit, the default locale will be used.
    """
    if not encoding:
        encoding = defaultencoding
    if not isinstance(string, types.UnicodeType):
        return unicode(string, encoding)
    else:
        return string
unicode_string = decode_string

def encode_string(string, encoding=None):
    """convert unicode to string

    If the second parameter encoding is omit, the default locale will be used.
    """
    if not encoding:
        encoding = defaultencoding
    if isinstance(string, types.UnicodeType):
        return string.encode(encoding)
    else:
        return string

